package com.inet.receiver;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import com.google.zxing.WriterException;
import com.inet.consoleservices.MyApplication;
import com.inet.util.HttpUtil;
import com.inet.util.L;
import com.inet.util.Utils;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ImageView;

public class MyBroadcastReceiver extends BroadcastReceiver {
	public static final String LOW_POWER = "android.intent.action.LOWPOWER_ON_KEYEVENT";
	public static final String LOW_POWER_OFF = "android.intent.action.LOWPOWER_OFF_KEYEVENT";
	public final static String ASK_FOR_PICTURE = "action.colink.take.picture";
	public final static String ASK_FOR_VEDIO = "action.colink.take.video";
	public final static String RECEIVE_PICTURE = "action.colink.upload.picture";
	public final static String RECEIVE_VEDIO = "action.colink.upload.video";
	public static final String ACTION_ACC_ON_KEYEVENT = "android.intent.action.ACC_ON_KEYEVENT";
	public static final String ACTION_ACC_OFF_KEYEVENT = "android.intent.action.ACC_OFF_KEYEVENT";
	private MyHandler mHandler;
	private Context mContext;
	private String open_id;

	public MyBroadcastReceiver() {

	}

	public MyBroadcastReceiver(MyHandler handler) {
		mHandler = handler;
	}

	@Override
	public void onReceive(final Context context, Intent intent) {
		if (LOW_POWER.equals(intent.getAction())) {
			try {
				mHandler.sendEmptyMessageDelayed(0, 2000);
			} catch (Exception e) {
			}
		} else if (LOW_POWER_OFF.equals(intent.getAction())) {
			try {
				mHandler.removeMessages(0);
			} catch (Exception e) {
			}
		} else if (RECEIVE_PICTURE.equals(intent.getAction())) {
			// 获取到Camera反馈回来的消息；

			final String path = intent.getExtras().getString("FILE_NAME");
			try {
				open_id = intent.getExtras().getString("OPEN_ID");
				L.i("MyBroadcastReceiver:open_id ==" + open_id);
			} catch (Exception e) {
			}
			new Thread(new Runnable() {

				@Override
				public void run() {
					PushOption.upLoadPhotoOrVideo(context, "getPhoto", path,
							open_id);
				}
			}).start();
		} else if (RECEIVE_VEDIO.equals(intent.getAction())) {
			// 获取到Camera反馈回来的消息；
			final String path = intent.getExtras().getString("FILE_NAME");
			final String open_id = intent.getExtras().getString("OPEN_ID");
			new Thread(new Runnable() {

				@Override
				public void run() {
					PushOption.upLoadPhotoOrVideo(context, "getVideo", path,
							open_id);
				}
			}).start();

		} else if (ACTION_ACC_ON_KEYEVENT.equals(intent.getAction())) {
			try {
				// 震动间隔时间清除
				Utils.lastUploadTime = 0;
//				if (MyApplication.StartACCON) {
//					L.i("MyBroadcastReceiver:action==" + intent.getAction());
//					MyApplication.StartACCON = false;
//
//				}
			} catch (Exception e) {
				L.i("MyBroadcastReceiver: e==" + e.toString());
			}
		} else if (ACTION_ACC_OFF_KEYEVENT.equals(intent.getAction())) {
//			L.i("MyBroadcastReceiver:action==" + intent.getAction());
//			try {
//				MyApplication.StartACCON = true;
//			} catch (Exception e) {
//			}
		}
	}

}
